package com.hunt.app.task;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hunt.service.app.FinancialDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ww
 * @className
 * @description
 * @date 2020/11/4
 */

//@Component
public class FinancialDataTask {

    private static final Logger log = LoggerFactory.getLogger(FinancialDataTask.class);

    @Autowired
    private FinancialDataService financialDataService;

    //每天9:00点执行
//    @Scheduled(cron = "0 0 9 * * ? ")
    public void taskStarter() {

        log.info("每日将财务数据读取到内存中的定时器启动...");
        try {
            Date date = new Date();
            String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(date);
            financialDataService.updateMemoryFinancialData(dateStr);
        }catch (Exception e){
            log.info("更新财务数据定时器执行失败,并已经释放执行锁");
            e.printStackTrace();
        }
    }
}
